package com.edu.web.user;


import com.edu.entity.blog.Article;
import com.edu.entity.chat.Chat;
import com.edu.entity.queryanswer.Query;
import com.edu.entity.resource.Resource;
import com.edu.entity.shop.Video;
import com.edu.entity.user.EduUser;
import com.edu.service.blog.ArticleService;
import com.edu.service.chat.EduChatService;
import com.edu.service.load.LoadService;
import com.edu.service.queryanswer.QueryService;
import com.edu.service.shop.VideoService;
import com.edu.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.security.Principal;
import java.util.List;
import java.util.Queue;

@Controller
public class EduUserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private QueryService queryService;
    @Autowired
    private LoadService loadService;
    @Autowired
    private VideoService videoService;
    @Autowired
    private EduChatService eduChatService;
    @RequestMapping("/login")
    public  String login(){
        return "login";
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/userhome")
    public String userhome(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Article> articleList=articleService.pageList();
        model.addAttribute("bloglists",articleList);
        System.out.println(articleList);
        return "user/index";
    }
    @RequestMapping("/scblog")
    public String scblog(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Article> articleList=articleService.pageList();
        model.addAttribute("bloglists",articleList);
        System.out.println(articleList);
        return "user/shoucangblog";
    }
    @RequestMapping("/userquery")
    public String userquery(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Query> queryList=queryService.pageList();
        model.addAttribute("querylists",queryList);
        return "user/question";
    }

    @RequestMapping("/useranswer")
    public String useranswer(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Query> queryList=queryService.pageList();
        model.addAttribute("querylists",queryList);
        return "user/answer";
    }

    @RequestMapping("/userdownload")
    public String userdownload(Model model, Principal principal,Integer page,Integer size){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Resource> resourceList=loadService.findlist(page,size);
        model.addAttribute("resourcelists",resourceList);
        return "user/download";
    }
    @RequestMapping("/uservideo")
    public String uservideo(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Video> videoList=videoService.pageList();
        model.addAttribute("videolists",videoList);
        return "user/vedio";
    }

    @RequestMapping("/userchat")
    public String userchat(Model model, Principal principal){
        EduUser eduUser=userService.findUserByName(principal.getName());
        model.addAttribute("userinfo",eduUser);
        List<Chat> chatList=eduChatService.pageList();
        model.addAttribute("chatLists",chatList);
        return "user/myChat";
    }
}
